﻿Imports System.Data
Imports System.Data.SqlClient

Public Class Frm_Modif_Demande_Clients
    Public num As Integer = -1
    Public Sub vider()
        If Comb_salle.Items.Count > 0 Then
            Comb_salle.SelectedIndex = 0
        End If

        If Combo_type_reserv.Items.Count > 0 Then
            Combo_type_reserv.SelectedIndex = 0
        End If

        If Comb_motif_reserv.Items.Count > 0 Then
            Comb_motif_reserv.SelectedIndex = 0
        End If
        txt_prix_salle.Text = 0
        txt_n_demande.Clear()
        txt_remarq.Clear()
        List_Repas.Items.Clear()
        List_tous.Items.Clear()
        txtPrixAdjoint.Clear()
        If cmbAdjoint.Items.Count > 0 Then
            cmbAdjoint.SelectedIndex = 0
        End If
        lstViewAdjoint.Items.Clear()
    End Sub

    Public Sub Comb_Motif_Reservation()
        Try
            Comb_motif_reserv.Items.Clear()
            Cmd = New SqlCommand("Select * From Comb_Motif_Reservation", Con)
            open()
            Dr = Cmd.ExecuteReader()
            If Dr.HasRows Then
                Do While Dr.Read()
                    Comb_motif_reserv.Items.Add(Dr("Motif_Reservation"))
                Loop
            End If
            Dr.Close()
            cnClose()

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try
    End Sub

    Public Sub Comb_autre_Equipement()
        Try
            Comb_Nom_Equipement.Items.Clear()
            Cmd = New SqlCommand("Select * From Comb_Equipement_Clients", Con)
            open()
            Dr = Cmd.ExecuteReader()
            Do While Dr.Read()
                Comb_Nom_Equipement.Items.Add(Dr("autre_Equipe"))
            Loop
            Dr.Close()
            cnClose()
            If Comb_Nom_Equipement.Items.Count > 0 Then
                Comb_Nom_Equipement.SelectedIndex = 0
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try
    End Sub

    'Public Sub Comb_Entrer()
    '    Try
    '        Comb_apperitif.Items.Clear()
    '        Cmd = New SqlCommand("Select * From Comb_Entrer", Con)
    '        open()
    '        Dr = Cmd.ExecuteReader()
    '        If Dr.HasRows Then
    '            Do While Dr.Read()
    '                Comb_apperitif.Items.Add(Dr("Entrer"))
    '            Loop
    '        End If
    '        Dr.Close()
    '        cnClose
    '        If Comb_apperitif.Items.Count > 0 Then
    '            Comb_apperitif.SelectedIndex = 0
    '        End If
    '    Catch ex As Exception
    '        MsgBox(ex.Message, MsgBoxStyle.Exclamation)
    '        cnClose
    '    End Try
    'End Sub

    Public Sub Comb_Plats()
        Try
            Comb_Repas.Items.Clear()
            Cmd = New SqlCommand("Select * From Comb_Plat", Con)
            open()
            Dr = Cmd.ExecuteReader()
            If Dr.HasRows Then
                Do While Dr.Read()
                    Comb_Repas.Items.Add(Dr("Plat"))
                Loop
            End If
            Dr.Close()
            cnClose()
            If Comb_Repas.Items.Count > 0 Then
                Comb_Repas.SelectedIndex = 0
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try
    End Sub

    'Public Sub Comb_apre()
    '    Try
    '        Comb_apres.Items.Clear()
    '        Cmd = New SqlCommand("Select * From Comb_Apres", Con)
    '        open()
    '        Dr = Cmd.ExecuteReader()
    '        If Dr.HasRows Then
    '            Do While Dr.Read()
    '                Comb_apres.Items.Add(Dr("Apres"))
    '            Loop
    '        End If
    '        Dr.Close()
    '        cnClose
    '        If Comb_apres.Items.Count > 0 Then
    '            Comb_apres.SelectedIndex = 0
    '        End If
    '    Catch ex As Exception
    '        MsgBox(ex.Message, MsgBoxStyle.Exclamation)
    '        cnClose
    '    End Try
    'End Sub

    'Public Sub Comb_desser()
    '    Try
    '        Comb_dessert.Items.Clear()
    '        Cmd = New SqlCommand("Select * From Comb_Dessert", Con)
    '        open()
    '        Dr = Cmd.ExecuteReader()
    '        If Dr.HasRows Then
    '            Do While Dr.Read()
    '                Comb_dessert.Items.Add(Dr("Dessert"))
    '            Loop
    '        End If
    '        Dr.Close()
    '        cnClose
    '        If Comb_dessert.Items.Count > 0 Then
    '            Comb_dessert.SelectedIndex = 0
    '        End If
    '    Catch ex As Exception
    '        MsgBox(ex.Message, MsgBoxStyle.Exclamation)
    '        cnClose
    '    End Try
    'End Sub

    Private Sub Frm_Rech_Demande_Clients_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Comb_autre_Equipement()
            Comb_Motif_Reservation()
            Comb_Plats()

            'tarik
            open()

            remplirCmbAdjoint(cmbAdjoint)


            For Each eventAdj In eventAdjoinLst
                For Each adj In lstAdjoints
                    If adj.idAdjoint = eventAdj.idAdjoint Then
                        lstViewAdjoint.Items.Add(New ListViewItem(New String() {adj.idAdjoint, adj.nom & " " & adj.prenom, adj.professino, eventAdj.prix}))
                        Exit For
                    End If
                Next
            Next
            Dr.Close()
            'end adjoint
            'end


            comb_client.Items.Clear()
            Cmd = New SqlCommand("Select * From Clients", Con)
            Dr = Cmd.ExecuteReader()
            Do While Dr.Read()
                If Dr("Type_Client") = "Entreprise" Then
                    comb_client.Items.Add(Dr("Nom_entreprise"))
                Else
                    comb_client.Items.Add(Dr("Nom") & "  " & Dr("Prenom"))
                End If
            Loop
            Dr.Close()
            cnClose()
            If comb_client.Items.Count > 0 Then
                comb_client.SelectedIndex = 0
            End If
        Catch ex As Exception

            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try
    End Sub
    Private Sub btn_supp_apres_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        For Each i As ListViewItem In List_Repas.SelectedItems
            List_Repas.Items.Remove(i)
        Next
    End Sub
    Private Sub Comb_salle_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Comb_salle.KeyPress
        e.Handled = True
    End Sub

    Private Sub Comb_salle_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Comb_salle.SelectedIndexChanged
        If Comb_salle.SelectedItem = "Salle 1" Then
            txt_adresse.Clear()
            txt_adresse.Enabled = False
            Combo_type_reserv.Items.Clear()
            Combo_type_reserv.Items.Add("Salle Vide")
            Combo_type_reserv.Items.Add("Salle Avec Matériels")
            Combo_type_reserv.Items.Add("Salle Avec Matériels et Repas")
            Combo_type_reserv.SelectedIndex = 0
            txt_prix_salle.Enabled = True
        ElseIf Comb_salle.SelectedItem = "Salle 2" Then
            txt_adresse.Clear()
            txt_adresse.Enabled = False
            Combo_type_reserv.Items.Clear()
            Combo_type_reserv.Items.Add("Salle Vide")
            Combo_type_reserv.Items.Add("Salle Avec Matériels")
            Combo_type_reserv.Items.Add("Salle Avec Matériels et Repas")
            Combo_type_reserv.SelectedIndex = 0
            txt_prix_salle.Enabled = True
        ElseIf Comb_salle.SelectedItem = "Autre Salle" Then
            txt_adresse.Enabled = True
            Combo_type_reserv.Items.Clear()
            Combo_type_reserv.Items.Add("Matériels et Repas")
            Combo_type_reserv.Items.Add("Salle Avec Matériels et Repas")
            Combo_type_reserv.SelectedIndex = 0
            txt_prix_salle.Enabled = False
            txt_prix_salle.Text = 0
        ElseIf Comb_salle.SelectedItem = "Domicile" Then
            txt_adresse.Enabled = True
            txt_adresse.Enabled = True
            Combo_type_reserv.Items.Clear()
            Combo_type_reserv.Items.Add("Matériels et Repas")
            Combo_type_reserv.SelectedIndex = 0
            txt_prix_salle.Enabled = False
            txt_prix_salle.Text = 0
        End If
    End Sub
    Private Sub comb_client_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles comb_client.KeyPress
        e.Handled = True
    End Sub

    Private Sub Combo_type_reserv_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Combo_type_reserv.KeyPress
        e.Handled = True
    End Sub

    Private Sub Comb_motif_reserv_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Comb_motif_reserv.KeyPress
        e.Handled = True
    End Sub
    Private Sub btn_rech_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_rech.Click
        Me.Enabled = False
        Frm_Recherche_clients.Show()
        rech = "Modif demande"
    End Sub

    'Private Sub btn_ajou_apres_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    '    Dim Line As ListViewItem = New ListViewItem(New String() {Comb_apres.SelectedItem, "Aprés"})
    '    List_Repas.Items.Add(Line)
    'End Sub
    Private Sub btn_ajou_equip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_ajou_equip.Click
        If txt_nbr.Text <> "" And txt_prix_unit.Text <> "" Then
            Dim Line As ListViewItem = New ListViewItem(New String() {Comb_Nom_Equipement.SelectedItem, txt_prix_unit.Text, txt_nbr.Text, txt_prix_total.Text, txt_remarq_matr.Text})
            List_tous.Items.Add(Line)
            txt_prix_unit.Clear()
            txt_nbr.Clear()
            txt_prix_total.Clear()
            txt_remarq_matr.Clear()
        End If

    End Sub

    Private Sub btn_supp_equip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_supp_equip.Click
        For Each i As ListViewItem In List_tous.SelectedItems
            List_tous.Items.Remove(i)
        Next
        txt_prix_unit.Clear()
        txt_nbr.Clear()
        txt_prix_total.Clear()
        txt_remarq.Clear()
    End Sub
    Private Sub Comb_apperitif_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        e.Handled = True
    End Sub

    Private Sub Comb_plat_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        e.Handled = True
    End Sub

    Private Sub Comb_apres_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        e.Handled = True
    End Sub

    Private Sub Comb_dessert_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        e.Handled = True
    End Sub

    Private Sub Comb_Nom_Equipement_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Comb_Nom_Equipement.KeyPress
        e.Handled = True
    End Sub
    Private Sub txt_prix_unit_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_prix_unit.TextChanged
        Dim selStart As Integer = txt_prix_unit.SelectionStart
        Dim selMoveLeft As Integer = 0
        Dim newStr As String = "" 'Build a new string by copying each valid character from the existing string. The new string starts as blank and valid characters are added 1 at a time.

        For i As Integer = 0 To txt_prix_unit.Text.Length - 1

            If "0123456789,".IndexOf(txt_prix_unit.Text(i)) <> -1 Then 'Characters that are in the allowed set will be added to the new string.
                newStr = newStr & txt_prix_unit.Text(i)

            ElseIf i < selStart Then 'Characters that are not valid are removed - if these characters are before the cursor, we need to move the cursor left to account for their removal.
                selMoveLeft = selMoveLeft + 1

            End If
        Next

        txt_prix_unit.Text = newStr 'Place the new text into the textbox.
        txt_prix_unit.SelectionStart = selStart - selMoveLeft 'Move the cursor to the appropriate location.


        If txt_prix_unit.Text = "" Then
            txt_prix_total.Text = 0
        End If

        Try
            If txt_prix_unit.Text <> "" And txt_nbr.Text <> "" Then
                txt_prix_total.Text = CDbl(txt_prix_unit.Text) * CDbl(txt_nbr.Text)
            End If

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try

    End Sub
    Private Sub txt_nbr_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_nbr.TextChanged
        Dim selStart As Integer = txt_nbr.SelectionStart
        Dim selMoveLeft As Integer = 0
        Dim newStr As String = "" 'Build a new string by copying each valid character from the existing string. The new string starts as blank and valid characters are added 1 at a time.

        For i As Integer = 0 To txt_nbr.Text.Length - 1

            If "0123456789,".IndexOf(txt_nbr.Text(i)) <> -1 Then 'Characters that are in the allowed set will be added to the new string.
                newStr = newStr & txt_nbr.Text(i)

            ElseIf i < selStart Then 'Characters that are not valid are removed - if these characters are before the cursor, we need to move the cursor left to account for their removal.
                selMoveLeft = selMoveLeft + 1

            End If
        Next

        txt_nbr.Text = newStr 'Place the new text into the textbox.
        txt_nbr.SelectionStart = selStart - selMoveLeft 'Move the cursor to the appropriate location.


        If txt_nbr.Text = "" Then
            txt_prix_total.Text = 0
        End If

        Try
            If txt_prix_unit.Text <> "" And txt_nbr.Text <> "" Then
                txt_prix_total.Text = CDbl(txt_prix_unit.Text) * CDbl(txt_nbr.Text)
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try

    End Sub

    Private Sub txt_prix_salle_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_prix_salle.TextChanged
        Dim selStart As Integer = txt_prix_salle.SelectionStart
        Dim selMoveLeft As Integer = 0
        Dim newStr As String = "" 'Build a new string by copying each valid character from the existing string. The new string starts as blank and valid characters are added 1 at a time.

        For i As Integer = 0 To txt_prix_salle.Text.Length - 1

            If "0123456789,".IndexOf(txt_prix_salle.Text(i)) <> -1 Then 'Characters that are in the allowed set will be added to the new string.
                newStr = newStr & txt_prix_salle.Text(i)

            ElseIf i < selStart Then 'Characters that are not valid are removed - if these characters are before the cursor, we need to move the cursor left to account for their removal.
                selMoveLeft = selMoveLeft + 1

            End If
        Next

        txt_prix_salle.Text = newStr 'Place the new text into the textbox.
        txt_prix_salle.SelectionStart = selStart - selMoveLeft 'Move the cursor to the appropriate location.


        If txt_prix_salle.Text = "" Then
            txt_prix_salle.Text = 0
        End If
    End Sub

    Private Sub btn_modif_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_modif.Click
        If Con.State = ConnectionState.Open Then
            cnClose()
        End If
        Try
            Cmd = New SqlCommand("Select * From Clients where Location='Non'", Con)
            open()
            Dr = Cmd.ExecuteReader()
            Do While Dr.Read()

                If Dr("Nom_entreprise") = comb_client.SelectedItem.ToString Then
                    num = Dr("Id_Client")
                ElseIf (Dr("Nom") & "  " & Dr("Prenom")) = comb_client.SelectedItem.ToString Then
                    num = Dr("Id_Client")
                End If
            Loop
            Dr.Close()
            cnClose()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try


        If txt_n_demande.Text <> "" Then
            If (Combo_type_reserv.SelectedItem <> "Salle Vide") Or (Combo_type_reserv.SelectedItem = "Salle Vide" And txt_prix_salle.Text <> 0) Then
                If MsgBox("Vous Voulez Vraiment Modifier La Demande ?", MsgBoxStyle.YesNo Or MsgBoxStyle.Information, "Modifier La Demande") = MsgBoxResult.Yes Then
                    Try
                        Cmd = New SqlCommand("update Clients_Demande set Date_evenement=@Date_evenement,lieu=@lieu,adresse=@adresse,Id_Client=@Id_Client,jour_nuit=@jour_nuit,N_demande=@N_demande,Motif_Reservation=@Motif_Reservation,Type_Reservation=@Type_Reservation,Prix_salle=@Prix_salle,Remarque=@Remarque,Date_reservation=@Date_reservation,Marie=@Marie,Mariee=@Mariee" & _
                         " Where id_dem=" & modif, Con)

                        Cmd.Parameters.Add("@Date_evenement", SqlDbType.Date).Value = CDate(txt_evenement.Text)
                        Cmd.Parameters.Add("@lieu", SqlDbType.VarChar).Value = Comb_salle.SelectedItem
                        If Comb_salle.SelectedItem = "Salle 1" Or Comb_salle.SelectedItem = "Salle 2" Then
                            Cmd.Parameters.Add("@adresse", SqlDbType.VarChar).Value = "laylat al omr"
                        Else
                            Cmd.Parameters.Add("@adresse", SqlDbType.VarChar).Value = txt_adresse.Text
                        End If
                        Cmd.Parameters.Add("@Id_Client", SqlDbType.Int).Value = num
                        If Radio_nuit.Checked = True Then
                            Cmd.Parameters.Add("@jour_nuit", SqlDbType.VarChar).Value = "Nuit"
                        ElseIf Radio_jour.Checked = True Then
                            Cmd.Parameters.Add("@jour_nuit", SqlDbType.VarChar).Value = "Jour"
                        End If
                        Cmd.Parameters.Add("@N_demande", SqlDbType.VarChar).Value = txt_n_demande.Text
                        Cmd.Parameters.Add("@Type_Reservation", SqlDbType.VarChar).Value = Combo_type_reserv.SelectedItem
                        Cmd.Parameters.Add("@Motif_Reservation", SqlDbType.VarChar).Value = Comb_motif_reserv.SelectedItem
                        Cmd.Parameters.Add("@Remarque", SqlDbType.Text).Value = txt_remarq.Text
                        Cmd.Parameters.Add("@Date_reservation", SqlDbType.Date).Value = CDate(txt_reserv.Text)
                        Cmd.Parameters.Add("@Prix_salle", SqlDbType.Float).Value = CDbl(txt_prix_salle.Text)
                        Cmd.Parameters.Add("@Marie", SqlDbType.VarChar).Value = txt_NomA.Text
                        Cmd.Parameters.Add("@Mariee", SqlDbType.VarChar).Value = txt_NomB.Text

                        open()
                        Cmd.ExecuteNonQuery()
                        'Tarik
                        'modifier par kirat
                        'code pour ajouter l'adjoint
                        If lstViewAdjoint.Items.Count > 0 Then
                            Cmd.CommandText = "INSERT INTO [adjointEvenement]([idAdjoint],[id_dem],[prix]) " &
                                                "VALUES(@idAdjoint,@id_dem,@prix)"
                            Cmd.Parameters.Clear()
                            Cmd.Parameters.Add("@id_dem", SqlDbType.Int).Value = modif
                            Cmd.Parameters.Add("@idAdjoint", SqlDbType.Int)
                            Cmd.Parameters.Add("@prix", SqlDbType.Float)
                            Dim flag As Boolean = False
                            For Each it As ListViewItem In lstViewAdjoint.Items
                                flag = False
                                For Each eventAdj In eventAdjoinLst
                                    If CInt(it.SubItems(0).Text) = eventAdj.idAdjoint Then
                                        flag = True
                                        Exit For
                                    End If
                                Next
                                If Not flag Then
                                    Cmd.Parameters("@idAdjoint").Value = CInt(it.SubItems(0).Text)
                                    Cmd.Parameters("@prix").Value = CDbl(it.SubItems(3).Text)
                                    Cmd.ExecuteNonQuery()
                                    eventAdjoinLst.Add(New adjointEvents With {.id_dem = modif, .idAdjoint = CInt(it.SubItems(0).Text), .prix = CDbl(it.SubItems(3).Text)})
                                End If
                            Next
                        End If

                        'Supprimer les adjoints
                        Dim lstTampon As New List(Of adjointEvents)
                        Dim flag2 As Boolean = False
                        For Each eventAdj In eventAdjoinLst
                            flag2 = False
                            For Each it As ListViewItem In lstViewAdjoint.Items
                                If eventAdj.idAdjoint = CInt(it.SubItems(0).Text) Then
                                    flag2 = True
                                    Exit For
                                End If
                            Next
                            If Not flag2 Then
                                Cmd.Parameters.Clear()
                                Cmd.CommandText = "delete from adjointEvenement where idAdjoint = " & eventAdj.idAdjoint
                                Cmd.ExecuteNonQuery()
                                lstTampon.Add(eventAdj)
                            End If
                        Next

                        For Each adjEvenTamp In lstTampon
                            eventAdjoinLst.Remove(adjEvenTamp)
                        Next

                        'end code
                        'end
                        cnClose()

                    Catch ex As Exception
                        If ex.Message = "Violation of UNIQUE KEY constraint 'uniq_Clients_Demande'. Cannot insert duplicate key in object 'dbo.Clients_Demande'." & vbNewLine & "The statement has been terminated." Then
                            MsgBox("La date est Reservée", MsgBoxStyle.Exclamation)
                            cnClose()
                            Exit Sub
                        Else
                            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                            cnClose()
                            Exit Sub
                        End If

                    End Try
                    '________________________________________________________________________'

                    Try
                        Cmd = New SqlCommand("Delete From Clients_Equip Where id_dem =" & modif, Con)
                        open()
                        Cmd.ExecuteNonQuery()
                        cnClose()
                    Catch ex As Exception
                        MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                        cnClose()
                    End Try
                    '________________________________________________________________________'

                    Try
                        Cmd = New SqlCommand("Delete From Clients_Repas Where id_dem =" & modif, Con)
                        open()
                        Cmd.ExecuteNonQuery()
                        cnClose()
                    Catch ex As Exception
                        MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                        cnClose()
                    End Try
                    '________________________________________________________________________'
                    Try
                        For i As Integer = 0 To List_tous.Items.Count - 1
                            Cmd = New SqlCommand("insert into Clients_Equip values (@id_dem,@Equipement,@Nbr,@Prix_Unitaire,@Prix_Total,@Remarq)", Con)
                            Cmd.Parameters.Add("@id_dem", SqlDbType.Int).Value = modif
                            Cmd.Parameters.Add("@Equipement", SqlDbType.VarChar).Value = List_tous.Items(i).SubItems(0).Text
                            Cmd.Parameters.Add("@Prix_Unitaire", SqlDbType.Float).Value = List_tous.Items(i).SubItems(1).Text
                            Cmd.Parameters.Add("@Nbr", SqlDbType.Float).Value = List_tous.Items(i).SubItems(2).Text
                            Cmd.Parameters.Add("@Prix_Total", SqlDbType.Float).Value = List_tous.Items(i).SubItems(3).Text
                            Cmd.Parameters.Add("@Remarq", SqlDbType.Text).Value = List_tous.Items(i).SubItems(4).Text

                            open()
                            Cmd.ExecuteNonQuery()
                            cnClose()

                        Next
                    Catch ex As Exception
                        MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                        cnClose()
                    End Try
                    '________________________________________________________________________'
                    Try
                        For i As Integer = 0 To List_Repas.Items.Count - 1
                            Cmd = New SqlCommand("insert into Clients_Repas values (@id_dem,@Repas)", Con)
                            Cmd.Parameters.Add("@id_dem", SqlDbType.Int).Value = modif
                            Cmd.Parameters.Add("@Repas", SqlDbType.VarChar).Value = List_Repas.Items(i).SubItems(0).Text


                            open()
                            Cmd.ExecuteNonQuery()
                            cnClose()
                        Next
                        num = -1
                        'vider()
                        MsgBox("Demande Modifier", MsgBoxStyle.Information, "Réussi !")

                    Catch ex As Exception
                        MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                        cnClose()
                    End Try


                End If
            Else
                MsgBox("Entrez les Données", MsgBoxStyle.Critical, "Erreur !")
            End If
        Else
            MsgBox("Entrez les Données", MsgBoxStyle.Critical, "Erreur !")
        End If
    End Sub

    Private Sub btn_Rechrcher_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Rechrcher.Click
        Frm_liste_Demande.MdiParent = Frm_Main
        Frm_liste_Demande.Show()
        liste = "demande"
        Me.Close()
    End Sub


    Private Sub btn_supp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_supp.Click
        If MsgBox("Voulez Vous Vraiment Supprimer cette Demande", MsgBoxStyle.YesNo Or MsgBoxStyle.Information, "Supprission !") = MsgBoxResult.Yes Then
            Try
                Cmd = New SqlCommand("Delete From Clients_Demande Where id_dem =" & modif, Con)
                open()
                Cmd.ExecuteNonQuery()
                'tarik
                Cmd.CommandText = "delete from locEvent where id = " & modif
                Cmd.ExecuteNonQuery()
                'end
                cnClose()
                vider()
                modif = 0
                MsgBox("Suppresion effectué !", MsgBoxStyle.Information, "Terminer")
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                cnClose()
            End Try
        End If

    End Sub

    Private Sub Combo_type_reserv_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Combo_type_reserv.SelectedIndexChanged
       
        If Combo_type_reserv.SelectedItem = "Salle Vide" Then
            Group_Matériels.Enabled = False
            Group_Repas.Enabled = False
        ElseIf Combo_type_reserv.SelectedItem = "Salle Avec Matériels" Then
            Group_Matériels.Enabled = True
            Group_Repas.Enabled = False
        ElseIf Combo_type_reserv.SelectedItem = "Salle Avec Matériels et Repas" Or Combo_type_reserv.SelectedItem = "Matériels et Repas" Then
            If Combo_type_reserv.SelectedItem = "Salle Avec Matériels et Repas" Then
                txt_prix_salle.Enabled = True
            End If
            If Combo_type_reserv.SelectedItem = "Matériels et Repas" Then
                txt_prix_salle.Enabled = False
            End If
            Group_Matériels.Enabled = True
            Group_Repas.Enabled = True
        ElseIf Combo_type_reserv.SelectedItem = "Repas" Then
            Group_Matériels.Enabled = False
            Group_Repas.Enabled = True

        End If
    End Sub

    Private Sub List_tous_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles List_tous.SelectedIndexChanged
        With List_tous
            If .SelectedIndices.Count > 0 Then
                For i As Integer = 0 To .SelectedIndices.Count - 1
                    Comb_Nom_Equipement.Text = (.Items(.SelectedIndices(i)).SubItems(0).Text)
                    txt_prix_unit.Text = (.Items(.SelectedIndices(i)).SubItems(1).Text)
                    txt_nbr.Text = (.Items(.SelectedIndices(i)).SubItems(2).Text)
                    txt_remarq_matr.Text = (.Items(.SelectedIndices(i)).SubItems(4).Text)

                Next
            End If
        End With
    End Sub

    Private Sub Comb_Nom_Equipement_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Comb_Nom_Equipement.SelectedIndexChanged
        If Comb_Nom_Equipement.Text = "Femmes de Ménage" And Comb_salle.Text = "Salle1" Then
            txt_nbr.Text = 3
        End If
        If Comb_Nom_Equipement.Text = "Femmes de Ménage" And Comb_salle.Text = "Salle2" Then
            txt_nbr.Text = 2
        End If
        If Comb_Nom_Equipement.Text = "Télévisions" And Comb_salle.Text = "Salle1" Then
            txt_nbr.Text = 4
        End If
        If Comb_Nom_Equipement.Text = "Télévisions" And Comb_salle.Text = "Salle2" Then
            txt_nbr.Text = 2
        End If
        If Comb_Nom_Equipement.Text = "Canapé salle" Then
            txt_nbr.Text = 10
        End If
        If Comb_Nom_Equipement.Text = "Piéce Monté" Then
            txt_nbr.Text = 1
        End If
        If Comb_Nom_Equipement.Text = "Orchestre" Then
            txt_nbr.Text = 1
        End If
        If Comb_Nom_Equipement.Text = "Berka du thé" Then
            txt_nbr.Text = 1
        End If
        If Comb_Nom_Equipement.Text = "Neggafa" Then
            txt_nbr.Text = 1
        End If
    End Sub

    Private Sub btn_ajou_apperitif_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub btn_ajou_apperitif_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_ajou_apperitif.Click
        repasExist = False
        For Each it As ListViewItem In List_Repas.Items
            If it.SubItems(0).Text = Comb_Repas.SelectedItem Then
                repasExist = True
                Exit For
            End If
        Next
        If Not repasExist Then
            Dim Line As ListViewItem = New ListViewItem(New String() {Comb_Repas.SelectedItem})
            List_Repas.Items.Add(Line)
        End If
    End Sub

    Private Sub btn_supp_apres_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_supp_apres.Click
        If List_Repas.SelectedItems.Count > 0 Then
            List_Repas.SelectedItems(0).Remove()
        End If
    End Sub

    Private Sub btnAddAdj_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddAdj.Click
        If Not String.IsNullOrWhiteSpace(txtPrixAdjoint.Text) And Not String.IsNullOrEmpty(txtPrixAdjoint.Text) Then

            For Each lstItem As ListViewItem In lstViewAdjoint.Items
                If CInt(lstItem.SubItems(0).Text) = CType(cmbAdjoint.SelectedItem, DictionaryEntry).Key Then
                    MsgBox("Déjà ajouter")
                    Exit Sub
                End If
            Next

            For Each adj In lstAdjoints
                If adj.idAdjoint = CType(cmbAdjoint.SelectedItem, DictionaryEntry).Key Then
                    lstViewAdjoint.Items.Add(New ListViewItem(New String() {adj.idAdjoint, adj.nom & " " & adj.prenom, adj.professino, txtPrixAdjoint.Text}))
                End If
            Next
            txtPrixAdjoint.Clear()
            cmbAdjoint.SelectedIndex = 0
        Else
            MsgBox("Vous devez entrer le prix!!!", MsgBoxStyle.Critical, "Erreur")
        End If
    End Sub

    Private Sub btnDeleteAdj_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteAdj.Click
        If lstViewAdjoint.SelectedItems.Count > 0 Then
            lstViewAdjoint.SelectedItems(0).Remove()
        End If
    End Sub

    Private Sub btnRechAdjoint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRechAdjoint.Click
        Me.Enabled = False
        frm = New Form
        frm = Me
        frmRechAdj.Show()
    End Sub

    Private Sub txtPrixAdjoint_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPrixAdjoint.KeyPress
        Dim allowedChars As String = "1234567890,"
        If txtPrixAdjoint.Text.Contains(",") Then
            allowedChars = "1234567890"
        End If
        If e.KeyChar = ChrW(8) Then
            e.Handled = False
        ElseIf allowedChars.IndexOf(e.KeyChar) = -1 Then
            e.Handled = True
        End If
    End Sub
End Class